package com.fanbuchi.app.ins.app;

import android.annotation.TargetApi;
import android.app.Application;
import android.os.Build;
import android.os.StrictMode;

import com.bugtags.library.Bugtags;
import com.bugtags.library.BugtagsOptions;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.backends.okhttp.OkHttpImagePipelineConfigFactory;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.decoder.SimpleProgressiveJpegConfig;
import com.fanbuchi.app.ins.BuildConfig;
import com.fanbuchi.app.ins.manager.OkHttpManager;
import com.igexin.sdk.PushManager;
import com.squareup.okhttp.OkHttpClient;

/**
 * Created by rabbit on 2016/3/16.
 */
public class Started extends Application {
   private static Started instance;



    public static Started getInstance() {
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Started.instance=this;
       // PushManager.getInstance().initialize(this.getApplicationContext());
        openBugtags();
        openFresco();
        if (BuildConfig.DEBUG){
            openStrictMode();
        }
    }

    private void openBugtags(){
        BugtagsOptions options = new BugtagsOptions.Builder().
                trackingLocation(true).//是否获取位置，默认 true
                trackingCrashLog(true).//是否收集crash，默认 true
                trackingConsoleLog(true).//是否收集console log，默认 true
                trackingUserSteps(true).//是否收集用户操作步骤，默认 true
                trackingNetworkURLFilter("(.*)").//自定义网络请求跟踪的 url 规则，默认 null
                build();
        Bugtags.start("7fe6a67c6702f7efe4a1abbc2e46618a", this, Bugtags.BTGInvocationEventBubble,options);
    }

    private void openFresco(){
        ImagePipelineConfig config=OkHttpImagePipelineConfigFactory.newBuilder(instance,OkHttpManager.getmOkHttpClient())//ImagePipelineConfig config = ImagePipelineConfig.newBuilder(this)
                .setDownsampleEnabled(true)
                .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
                /*.setBitmapMemoryCacheParamsSupplier(bitmapCacheParamsSupplier)
                .setCacheKeyFactory(cacheKeyFactory)
                .setEncodedMemoryCacheParamsSupplier(encodedCacheParamsSupplier)
                .setExecutorSupplier(executorSupplier)
                .setImageCacheStatsTracker(imageCacheStatsTracker)
                .setMainDiskCacheConfig(mainDiskCacheConfig)
                .setMemoryTrimmableRegistry(memoryTrimmableRegistry)
                .setNetworkFetchProducer(networkFetchProducer)
                .setPoolFactory(poolFactory)
                .setRequestListeners(requestListeners)
                .setSmallImageDiskCacheConfig(smallImageDiskCacheConfig)*/
                .build();

        //DiskCacheConfig、ImagePipelineConfig、MemoryCacheParams
        Fresco.initialize(instance,config);
    }


    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void openStrictMode() {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectCustomSlowCalls()

                .detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().penaltyFlashScreen()// API等级11
                .build());
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectCustomSlowCalls()
                .detectNetwork().penaltyLog().penaltyFlashScreen()// API等级11
                .build());

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
    }





}
